package cn.hamster3.hamsterworld.command;

import cn.hamster3.api.HamsterAPI;
import cn.hamster3.hamsterworld.core.DataManager;
import cn.hamster3.hamsterworld.core.Message;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class RebuildCommand extends CommandBase {
    public RebuildCommand(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public String getPermission() {
        return "hw.rebuild";
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        if (!HamsterAPI.hasMoney(player, dataManager.getRebuildWorldCost())) {
            player.sendMessage(Message.notEnoughMoney.toString()
                    .replace("%has%", String.format("%.2f", HamsterAPI.seeMoney(player)))
                    .replace("%need%", String.format("%.2f", dataManager.getRebuildWorldCost()))
            );
            return true;
        }
        if (dataManager.getWorldData(player) == null) {
            player.sendMessage(Message.notHasWorld.toString());
            return true;
        }
        dataManager.rebuildWorld(player);
        HamsterAPI.takeMoney(player, dataManager.getRebuildWorldCost());
        return true;
    }
}
